<!--
 * @Author: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @Date: 2022-08-23 20:53:29
 * @LastEditors: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @LastEditTime: 2022-08-25 14:57:27
 * @FilePath: \后端管理系统\app\src\views\Goods\Add.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <MyBreadcrumb :breadList="$route.meta.breadList" />
    <el-card class="box-card">
      <el-alert title="消息提示的文案" center type="info" show-icon> </el-alert>

      <el-steps :active="active" finish-status="success">
        <el-step title="基本信息"></el-step>
        <el-step title="商品参数"></el-step>
        <el-step title="商品属性"></el-step>
        <el-step title="商品图片"></el-step>
        <el-step title="商品内容"></el-step>
        <el-step title="完成"></el-step>
      </el-steps>

      <el-tabs
        tab-position="left"
        style="height: 500px"
        @tab-click="tabClick"
        :before-leave="beforeLeave"
      >
        <el-tab-pane label="基本信息" name="0">
          <AddForm
            :shopValues="shopValues"
            :ruleForm="ruleForm"
            v-on:submit_val="submitVal"
          />
        </el-tab-pane>
        <el-tab-pane label="商品参数" name="1">商品参数</el-tab-pane>
        <el-tab-pane label="商品属性" name="2">商品属性</el-tab-pane>
        <el-tab-pane label="商品图片" name="3">商品图片</el-tab-pane>
        <el-tab-pane label="商品内容" name="4">
          <quillEditor
            class="quillEditor"
            v-model="content"
            @blur="onEditorBlur($event)"
            ref="myQuillEditor"
          >
          </quillEditor>
          <el-button type="primary" @click="add">添加商品</el-button>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import MyBreadcrumb from "../../components/MyBreadcrumb.vue";
import AddForm from "./component/AddForm.vue";
import { httpAddCateGories } from '../../api/goods'
import { quillEditor } from "vue-quill-editor";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
export default {
  components: {
    MyBreadcrumb,
    AddForm,
    quillEditor,
  },
  data() {
    return {
      active: 1,
      shopValues: false,
      isActive: false,
      isShow: false,
      content: "",
      ruleForm: {
        goods_cat: "",
        goods_name: "",
        goods_price: 0,
        goods_number: 0,
        goods_weight: 0,
      },
      // cat_name:'',//分类名称
    };
  },
  methods: {
    // 校验 只有选择了选择器才能进行一下操作
    tabClick(ev) {
      if (!this.isActive) {
        this.active = 1;
        if (ev.index === "1") {
          this.shopValues = true;
        }
      } else {
        this.active = ev.index * 1;
      }
    },
    submitVal(val) {
      this.isShow = val;
    },
    beforeLeave(activeName, oldActiveName) {
      if (oldActiveName === "0" && !this.isShow) {
        this.$message.error("请填写所有信息！！！");
        this.isActive = false;
        return false;
      } else {
        this.isActive = true;
        return true;
      }
    },
    onEditorBlur(quill) {
      console.log();
    },
   async add() {
      const value={...this.ruleForm,goods_cat:`${this.ruleForm.goods_cat}`,goods_introduce:this.content};
      // const value=[{...this.ruleForm},{goods_cat:`${this.ruleForm.goods_cat}`},{goods_introduce:this.content}]
      const res=await httpAddCateGories('/goods',value);
      console.log(res)
      console.log(value)
    },
  },
};
</script>

<style>
.box-card,
.step,
.tabs {
  margin-top: 20px;
}

.ql-container .ql-snow {
  height: 400px;
}
</style>